package com.bw.lib_common.utils

import android.widget.ImageView
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bw.lib_common.R

/**
 * @Author : yaotianxue
 * @Time : On 2023/11/22 15:39
 * @Description : ImageAdapter
 */
object ImageAdapter {
    @JvmStatic
    @BindingAdapter("android:loadImage")
    fun loadImage(imageView: ImageView,url:String){
        Glide.with(imageView.context)
            .load(url)
            .placeholder(R.drawable.logo)
            .error(R.drawable.logo)
            .transform(CenterCrop())
            .into(imageView)
    }

    @JvmStatic
    @BindingAdapter("android:loadCircleImage")
    fun loadCircleImage(imageView: ImageView,url:String){
        Glide.with(imageView.context)
            .load(url)
            .placeholder(R.drawable.logo)
            .error(R.drawable.logo)
            .transform(CircleCrop())
            .into(imageView)
    }

    @JvmStatic
    @BindingAdapter("android:loadRoundedImage")
    fun loadRoundedImage(imageView: ImageView,url:String){
        Glide.with(imageView.context)
            .load(url)
            .placeholder(R.drawable.logo)
            .error(R.drawable.logo)
            .transform(CenterCrop(), RoundedCorners(20))
            .into(imageView)
    }

}